{% extends "base_generic.html" %}

{% block title %}作者列表 - 本地图书馆{% endblock %}

{% block content %}
<div class="card">
    <div class="card-header text-white" style="background-color: #ffb3eb;">
        <h1 class="h3 mb-0">
            <i class="fas fa-user me-2"></i>作者列表
        </h1>
    </div>
    <div class="card-body">
        {% if author_list %}
        <div class="row">
            {% for author in author_list %}
            <div class="col-md-6 mb-4">
                <div class="card h-100">
                    <div class="card-body">
                        <h5 class="card-title">
                            <a href="{{ author.get_absolute_url }}" class="text-decoration-none">
                                {{ author.name }}
                            </a>
                        </h5>
                        <p class="card-text">
                            {{ author.bio|truncatewords:30 }}
                        </p>
                    </div>
                    <div class="card-footer bg-transparent">
                        <a href="{{ author.get_absolute_url }}" class="btn btn-outline-primary btn-sm">
                            <i class="fas fa-info-circle me-1"></i>查看详情
                        </a>
                    </div>
                </div>

            </div>
            {% endfor %}
        </div>

        {% if is_paginated %}
        <nav aria-label="分页" class="mt-4">
            <ul class="pagination justify-content-center">
                {% if page_obj.has_previous %}
                <li class="page-item">
                    <a class="page-link" href="?page={{ page_obj.previous_page_number }}">
                        <i class="fas fa-chevron-left"></i>
                    </a>
                </li>
                {% endif %}

                {% for i in paginator.page_range %}
                <li class="page-item {% if page_obj.number == i %}active{% endif %}">
                    <a class="page-link" href="?page={{ i }}">{{ i }}</a>
                </li>
                {% endfor %}

                {% if page_obj.has_next %}
                <li class="page-item">
                    <a class="page-link" href="?page={{ page_obj.next_page_number }}">
                        <i class="fas fa-chevron-right"></i>
                    </a>
                </li>
                {% endif %}
            </ul>
        </nav>
        {% endif %}

        {% else %}
        <p class="text-muted">暂无作者信息。</p>
        {% endif %}

        {% if perms.catalog.add_author %}
        <div class="mt-4">
            <a href="{% url 'author-create' %}" class="btn btn-success">
                <i class="fas fa-plus me-1"></i>添加新作者
            </a>
        </div>
        {% endif %}

        <div class="mt-4">
            <a href="{% url 'index' %}" class="btn btn-outline-secondary">
                <i class="fas fa-arrow-left me-1"></i>返回首页
            </a>
        </div>
    </div>
</div>
{% endblock %}